<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/


if (!isset($_POST['text'])) exit ('Нет запроса');

$search = substr ( htmlspecialchars (urldecode ($_POST['text']), ENT_QUOTES), 0, 20);
$search_a = explode (' ', $search);
$search = $search_a[0];

if (mb_strlen($search) < 3) exit ('Введите больше 3-х символов');

$bad = array("!","*","%","(",")","=","<",">","?","/","\\","|","&",":",";","'",'"',",","`","~");
$bad_count = count($bad);
for ($i=0; $i<$bad_count; ++$i) {
	$search = str_replace ($bad[$i], '', $search);
}

$get = $db->query ("SELECT art_id, art_header FROM ".DB_PEREFIX."_articles WHERE art_header LIKE '%{$search}%' AND art_like_page = 'no' ORDER BY art_id DESC");

if ($db->num_rows ($get) > 0) {
	while (list ($id, $header) = $db->fetch_row ($get)) {
		$search = mb_strtolower (trim ($search));
		$header = preg_replace ("/".$search."/iu", "<strong>$search</strong>", $header);
		print '<a href="/articles/'.$id.'.html">'.$header.'</a>';
	}
}
else print 'Нет статей с таким заголовком';



exit;